package com.ai.txyun.deepseek;

import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import java.net.http.HttpRequest.BodyPublishers;
import java.net.http.HttpResponse.BodyHandlers;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ObjectNode;

public class DeepSeekClient {
    private static final String API_KEY = "sk-sadsad";
    private static final String API_URL = "https://api.deepseek.com/v1";

    public static void main(String[] args) throws Exception {
        // 创建 HTTP 客户端
        HttpClient client = HttpClient.newHttpClient();
        
        // 构建请求体 JSON
        ObjectMapper mapper = new ObjectMapper();
        ObjectNode requestBody = mapper.createObjectNode();
        
        requestBody.put("model", "deepseek-chat");
        requestBody.put("temperature", 1.3);
        requestBody.put("max_tokens", 1024);
        requestBody.put("stream", false);
        
        ObjectNode messages = mapper.createObjectNode();
        messages.putArray("messages")
            .addObject()
                .put("role", "user")
                .put("content", "张崇炼在族谱中属于哪个区域的后代");
        
        requestBody.set("messages", messages.get("messages"));
        
        // 创建 HTTP 请求
        HttpRequest request = HttpRequest.newBuilder()
                .uri(URI.create(API_URL))
                .header("Content-Type", "application/json")
                .header("Authorization", "Bearer " + API_KEY)
                .POST(BodyPublishers.ofString(mapper.writeValueAsString(requestBody)))
                .build();
        
        // 发送请求并获取响应
        HttpResponse<String> response = client.send(request, BodyHandlers.ofString());
        
        // 打印响应
        System.out.println("Status code: " + response.statusCode());
        System.out.println("Response body: " + response.body());
    }
}